home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / gcc / gcc261c.zoo / objects / CircularArrayPrivate.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-18  |  2.4 KB  |  76 lines

  1. /* CircularArray definitions for the use of subclass implementations
  2.    Copyright (C) 1993,1994 Free Software Foundation, Inc.
  3.  
  4.    Written by:  R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
  5.    Date: May 1993
  6.  
  7.    This file is part of the GNU Objective C Class Library.
  8.  
  9.    This library is free software; you can redistribute it and/or
  10.    modify it under the terms of the GNU Library General Public
  11.    License as published by the Free Software Foundation; either
  12.    version 2 of the License, or (at your option) any later version.
  13.    
  14.    This library is distributed in the hope that it will be useful,
  15.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17.    Library General Public License for more details.
  18.  
  19.    You should have received a copy of the GNU Library General Public
  20.    License along with this library; if not, write to the Free
  21.    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */ 
  23.  
  24. #ifndef __CircularArrayPrivate_h_INCLUDE_GNU
  25. #define __CircularArrayPrivate_h_INCLUDE_GNU
  26.  
  27. #include <objects/stdobjects.h>
  28. #include <objects/ArrayPrivate.h>
  29.  
  30. #define CIRCULAR_TO_BASIC(INDEX) \
  31.   ((INDEX + self->_start_index) % self->_capacity)
  32.  
  33. #define BASIC_TO_CIRCULAR(INDEX) \
  34.   ((INDEX + self->_capacity - self->_start_index) % self->_capacity)
  35.  
  36. #define NEXT_CIRCULAR_INDEX(INDEX) \
  37.   ((INDEX + 1) % self->_capacity)
  38.  
  39. #define PREV_CIRCULAR_INDEX(INDEX) \
  40.   ((INDEX + self->_capacity - 1) % self->_capacity)
  41.  
  42. static inline void
  43. circularMakeHoleAt(CircularArray *self, unsigned basicIndex)
  44. {
  45.   int i;
  46.   if (self->_start_index && basicIndex > self->_start_index)
  47.     {
  48.       for (i = self->_start_index; i < basicIndex; i++)
  49.     self->_contents_array[i-1] = self->_contents_array[i];
  50.     }
  51.   else
  52.     {
  53.       for (i = CIRCULAR_TO_BASIC(self->_count-1); i >= basicIndex; i--)
  54.     self->_contents_array[i+1] = self->_contents_array[i];
  55.     }
  56.   /* This is never called with _count == 0 */
  57. }
  58.  
  59. static inline void
  60. circularFillHoleAt(CircularArray *self, unsigned basicIndex)
  61. {
  62.   int i;
  63.   if (basicIndex > self->_start_index)
  64.     {
  65.       for (i = basicIndex; i > self->_start_index; i--)
  66.     self->_contents_array[i] = self->_contents_array[i-1];
  67.     }
  68.   else
  69.     {
  70.       for (i = basicIndex; i < CIRCULAR_TO_BASIC(self->_count-1); i++)
  71.     self->_contents_array[i] = self->_contents_array[i+1];
  72.     }
  73. }
  74.  
  75. #endif /* __CircularArrayPrivate_h_INCLUDE_GNU */
  76.